package com.qdsg.ysg.doctor.ui;

import android.widget.EditText;

import com.qdsg.ysg.doctor.util.AES128;
import com.qdsg.ysg.doctor.util.ToastUtil;
import com.rest.business.RestProxy;
import com.rest.response.BaseResponse;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.base.BaseActivity;

/**
 * Created by Administrator on 2020/2/9.
 */

public class RegisterActivity extends BaseActivity {
    @BindView(R.id.edt_name)
    EditText edt_name;

    @BindView(R.id.edt_code)
    EditText edt_code;
    @BindView(R.id.edt_phone)
    EditText edt_phone;
    @BindView(R.id.edt_id_card)
    EditText edt_id_card;
    @BindView(R.id.edt_password)
    EditText edt_password;


    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutResource() {
        return R.layout.aty_register;
    }

    @OnClick(R.id.btn_code)
    void btn_code() {
        getCode();
    }

    @OnClick(R.id.btn_save)
    void btn_save(){
        register();
    }

    private void getCode() {
        try {
            RestProxy.getInstance().getCode( AES128.encryptStringAES(edt_phone.getText().toString(),"7t3e506jaa10xbd4"), new Observer<BaseResponse>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(BaseResponse baseResponse) {

                }

                @Override
                public void onError(Throwable e) {
                    ToastUtil.onError( RegisterActivity.this,e);
                }

                @Override
                public void onComplete() {

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private void register() {
        try {
            RestProxy.getInstance().register( AES128.encryptStringAES(edt_name.getText().toString(),"7t3e506jaa10xbd4"), AES128.encryptStringAES(edt_id_card.getText().toString(),"7t3e506jaa10xbd4"), AES128.encryptStringAES(edt_password.getText().toString(),"7t3e506jaa10xbd4"), edt_code.getText().toString(), AES128.encryptStringAES(edt_phone.getText().toString(),"7t3e506jaa10xbd4"), new Observer<BaseResponse>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(BaseResponse baseResponse) {
                    finish();
                }

                @Override
                public void onError(Throwable e) {
                    ToastUtil.onError( RegisterActivity.this,e);

                }

                @Override
                public void onComplete() {

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
